﻿using System;
using System.Collections.ObjectModel;
using NHibernate.SqlTypes;

namespace ContactCenter.AuditEventListener
{
    [Serializable]
    public class AuditAction
    {
        public string AuditActionId { get; set; }
        public string AuditActionDescription { get; set; }

        public override string ToString()
        {
            return string.Format("{0} - {1}", AuditActionId, AuditActionDescription);
        }
    }

    [Serializable]
    public class AuditActions : ReadOnlyCollection<AuditAction>
    {
        public static AuditAction Inserted = new AuditAction { AuditActionId = "INS", AuditActionDescription = "Inserted" };
        public static AuditAction Modified = new AuditAction { AuditActionId = "MOD", AuditActionDescription = "Modified" };
        public static AuditAction Deleted = new AuditAction { AuditActionId = "DEL", AuditActionDescription = "Deleted" };

        public AuditActions()
            : base(new[] { Inserted, Modified, Deleted })
        { }
    }

    public class AuditActionType : GenericWellKnownInstanceType<AuditAction, string>
    {
        public AuditActionType()
            : base(new AuditActions(), (e, k) => e.AuditActionId == k, e => e.AuditActionId)
        { }

        public override SqlType[] SqlTypes
        {
            get { return new SqlType[] { SqlTypeFactory.GetString(3) }; }
        }
    }
}
